
//
//  UIBarButtonItem+XHBarButton.m
//  BaiSiBuDeJie
//
//  Created by xiaohui on 16/6/4.
//  Copyright © 2016年 xiaohui. All rights reserved.
//

#import "UIBarButtonItem+XHBarButton.h"

@implementation UIBarButtonItem (XHBarButton)

+ (UIBarButtonItem *)barButtonWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    UIButton  *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:image forState:UIControlStateNormal];
    //[button setImage:highlightedImage forState:UIControlStateHighlighted];
    [button setImage:highlightedImage forState:UIControlStateSelected];
    [button addTarget:target action:action forControlEvents:controlEvents];
    [button sizeToFit];    
    return  [[UIBarButtonItem alloc]initWithCustomView:button];
}

+(UIBarButtonItem *)barButtonWithImage:(UIImage  *)image highImage:(UIImage *)highImage type:(UIBarButtonItemType)type target:( nullable id)target action:(_Nonnull SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    //init the button
    UIButton  *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    if (type == UIBarButtonItemTypeHorizon) {
        button.frame = CGRectMake(0, 0, 50,18);
    }else if (type == UIBarButtonItemTypeRect) {
        button.frame = CGRectMake(0, 0, 25, 25);
    }
    
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setBackgroundImage:highImage forState:UIControlStateHighlighted];
    [button addTarget:target action:action forControlEvents:controlEvents];
    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

//+(UIBarButtonItem *)creatleftBarButtonItemWithSys:(NSString *)sys
//{
//    NSString*imageName = kLogoImageIcon;
//    if([sys isEqualToString:mDevAppId]){
//        imageName =@"LogoImageIconDev";
//    }else if([sys isEqualToString:mExperAppId]){
//        imageName =@"LogoImageIconExper";
//    }else if([sys isEqualToString:mTestAppId]){
//        imageName =@"LogoImageIconTest";
//    }
//    UIBarButtonItem  *leftItem = [UIBarButtonItem barButtonWithImage:[UIImage imageNamed:imageName] highlightedImage:[UIImage imageNamed:imageName] addTarget:self action:@selector(leftBarButtonItemClicked) forControlEvents:UIControlEventTouchUpInside];
//    return leftItem;
//}

+(UIBarButtonItem *)creatleftBarButtonItemWithImage:(NSString *)imageName
{
    UIBarButtonItem  *leftItem = [UIBarButtonItem barButtonWithImage:[UIImage imageNamed:imageName] highlightedImage:[UIImage imageNamed:imageName] addTarget:self action:@selector(leftBarButtonItemClicked) forControlEvents:UIControlEventTouchUpInside];
    
    return leftItem;
}
   
    
//左边
+(void)leftBarButtonItemClicked
{
    
    
}


@end
